package com.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.bean.Client;
import com.bean.User;
import com.service.ClientService;


@Controller
@RequestMapping("client")
public class ClientAction {
	
	@Autowired
	private ClientService clientService;
	
	
	@RequestMapping("list")
    public String log(String name,String phone,Model model){
		System.out.println("client进来了！！！！！！！！！！！！");
		Map<String, Object> map = new HashMap<String,Object>();
		if(name != null && "".equals(name.trim())){
			name = null;
		}
		if(phone != null && "".equals(phone.trim())){
			phone = null;
		}
		map.put("name", name);
		map.put("phone", phone);
		List<Client> list =	clientService.list(map);
		
		model.addAttribute("list", list);
		return "client/list";  
    }
	
	@RequestMapping("delete")
    public void delete(Integer id){
		clientService.delete(id);
    }
	
	@RequestMapping("toAdd")
    public String toAdd(){
		return "client/add";
    }
	
	@RequestMapping("add")
    public String add(Client bean){
		clientService.insert(bean);
		return "redirect:list.do";
    }
	
	@RequestMapping("toUpdate")
    public String toUpdate(Integer id,Model model){
		Client client = clientService.selectOne(id);
		model.addAttribute("client", client);
		return "client/update";
    }
	@RequestMapping("update")
    public String update(Client bean){
		clientService.update(bean);
		return "redirect:list.do";
    }
}
